//
//  staffModelJPieces.m
//
//  Created by 春程 王 on 16/8/3
//  Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//

#import "staffModelJPieces.h"


NSString *const kstaffModelJPiecesAreaCode = @"areaCode";
NSString *const kstaffModelJPiecesNameSender = @"nameSender";
NSString *const kstaffModelJPiecesOrderId = @"orderId";
NSString *const kstaffModelJPiecesId = @"id";
NSString *const kstaffModelJPiecesPhoneSender = @"phoneSender";
NSString *const kstaffModelJPiecesAddressRecipient = @"addressRecipient";
NSString *const kstaffModelJPiecesAddressSender = @"addressSender";
NSString *const kstaffModelJPiecesTimeAdd = @"timeAdd";


@interface staffModelJPieces ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation staffModelJPieces

@synthesize areaCode = _areaCode;
@synthesize nameSender = _nameSender;
@synthesize orderId = _orderId;
@synthesize jPiecesIdentifier = _jPiecesIdentifier;
@synthesize phoneSender = _phoneSender;
@synthesize addressRecipient = _addressRecipient;
@synthesize addressSender = _addressSender;
@synthesize timeAdd = _timeAdd;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.areaCode = [self objectOrNilForKey:kstaffModelJPiecesAreaCode fromDictionary:dict];
            self.nameSender = [self objectOrNilForKey:kstaffModelJPiecesNameSender fromDictionary:dict];
            self.orderId = [self objectOrNilForKey:kstaffModelJPiecesOrderId fromDictionary:dict];
            self.jPiecesIdentifier = [self objectOrNilForKey:kstaffModelJPiecesId fromDictionary:dict];
            self.phoneSender = [self objectOrNilForKey:kstaffModelJPiecesPhoneSender fromDictionary:dict];
            self.addressRecipient = [self objectOrNilForKey:kstaffModelJPiecesAddressRecipient fromDictionary:dict];
            self.addressSender = [self objectOrNilForKey:kstaffModelJPiecesAddressSender fromDictionary:dict];
            self.timeAdd = [self objectOrNilForKey:kstaffModelJPiecesTimeAdd fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.areaCode forKey:kstaffModelJPiecesAreaCode];
    [mutableDict setValue:self.nameSender forKey:kstaffModelJPiecesNameSender];
    [mutableDict setValue:self.orderId forKey:kstaffModelJPiecesOrderId];
    [mutableDict setValue:self.jPiecesIdentifier forKey:kstaffModelJPiecesId];
    [mutableDict setValue:self.phoneSender forKey:kstaffModelJPiecesPhoneSender];
    [mutableDict setValue:self.addressRecipient forKey:kstaffModelJPiecesAddressRecipient];
    [mutableDict setValue:self.addressSender forKey:kstaffModelJPiecesAddressSender];
    [mutableDict setValue:self.timeAdd forKey:kstaffModelJPiecesTimeAdd];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.areaCode = [aDecoder decodeObjectForKey:kstaffModelJPiecesAreaCode];
    self.nameSender = [aDecoder decodeObjectForKey:kstaffModelJPiecesNameSender];
    self.orderId = [aDecoder decodeObjectForKey:kstaffModelJPiecesOrderId];
    self.jPiecesIdentifier = [aDecoder decodeObjectForKey:kstaffModelJPiecesId];
    self.phoneSender = [aDecoder decodeObjectForKey:kstaffModelJPiecesPhoneSender];
    self.addressRecipient = [aDecoder decodeObjectForKey:kstaffModelJPiecesAddressRecipient];
    self.addressSender = [aDecoder decodeObjectForKey:kstaffModelJPiecesAddressSender];
    self.timeAdd = [aDecoder decodeObjectForKey:kstaffModelJPiecesTimeAdd];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_areaCode forKey:kstaffModelJPiecesAreaCode];
    [aCoder encodeObject:_nameSender forKey:kstaffModelJPiecesNameSender];
    [aCoder encodeObject:_orderId forKey:kstaffModelJPiecesOrderId];
    [aCoder encodeObject:_jPiecesIdentifier forKey:kstaffModelJPiecesId];
    [aCoder encodeObject:_phoneSender forKey:kstaffModelJPiecesPhoneSender];
    [aCoder encodeObject:_addressRecipient forKey:kstaffModelJPiecesAddressRecipient];
    [aCoder encodeObject:_addressSender forKey:kstaffModelJPiecesAddressSender];
    [aCoder encodeObject:_timeAdd forKey:kstaffModelJPiecesTimeAdd];
}

- (id)copyWithZone:(NSZone *)zone
{
    staffModelJPieces *copy = [[staffModelJPieces alloc] init];
    
    if (copy) {

        copy.areaCode = [self.areaCode copyWithZone:zone];
        copy.nameSender = [self.nameSender copyWithZone:zone];
        copy.orderId = [self.orderId copyWithZone:zone];
        copy.jPiecesIdentifier = [self.jPiecesIdentifier copyWithZone:zone];
        copy.phoneSender = [self.phoneSender copyWithZone:zone];
        copy.addressRecipient = [self.addressRecipient copyWithZone:zone];
        copy.addressSender = [self.addressSender copyWithZone:zone];
        copy.timeAdd = [self.timeAdd copyWithZone:zone];
    }
    
    return copy;
}


@end
